<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page import="java.sql.*" %>
<% request.setCharacterEncoding("UTF-8");%>
<%String id = request.getParameter("stuid");%>
<%String stuName = request.getParameter("stuname");%>
<%String stuBirthday = request.getParameter("stubirthday");%>
<%String stuClass = request.getParameter("stuclass");%>
<html>
<head>
    <title>条件查询</title>
    <%
        String dbName = "school";//数据库
        String userName = "root";//账户
        String userPassword= "123456";//密码
        String url = "jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPassword;
        Class.forName("com.mysql.cj.jdbc.Driver");//5.7以下不加.cj
        Connection conn = DriverManager.getConnection(url);//连接数据库
        Statement statement = conn.createStatement();//创建操作对象
        String sql = "insert into student values ('"+id+"','"+stuName+"','"+stuBirthday+"','"+stuClass+"')";
        int rsult = statement.executeUpdate(sql);//运行sql命令查询数据 结果放到rs结果集中
        if (rsult>0) {
            out.print("<script>alert('添加成功')</script>");
        }else {
            out.print("<script>alert('添加失败')</script>");
        }
        sql = "select * from student";
        ResultSet rs = null;
        rs = statement.executeQuery(sql);
    %>
<%-- 请勿在项目正式环境中引用该layui.css 地址   --%>
    <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet">
</head>
<body>
<table class="layui-table" lay-even>
<colgroup>学生信息表</colgroup>
<thead>
<tr>
    <th>学号</th>
    <th>姓名</th>
    <th>所在班级</th>
</tr>
</thead>
<tbody>
<% while (rs.next()) { %>
<tr>
    <td><%=rs.getString(1)%></td>
    <td><%=rs.getString(2)%></td>
    <td><%=rs.getString(3)%></td>
    <td><%=rs.getString(4)%></td>
</tr>
<% } %>
</tbody>
<%
    rs.close();
    statement.close();
    conn.close();
%>
</table>
</body>
</html>